<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>

<script>
    const canvas = document.createElement("canvas");
    canvas.width = 600;
    canvas.height = 400;
    document.body.append(canvas);
    const context = canvas.getContext("2d");

    let img = new Image();
    img.src = './images/jlt.png';
    img.onload = function () {
        //  387 735
        // context.drawImage(img, 0, 0, 150, 735, 0, 0, 150, 735)
        // context.drawImage(img, 130, 0, 150, 735, 0, 0, 150, 735)
        // context.drawImage(img, 130 * 2, 0, 150, 735, 0, 0, 150, 735)
        // context.drawImage(img, 130 * 3, 0, 150, 735, 0, 0, 150, 735)
        // context.drawImage(img, 130 * 4, 0, 150, 735, 0, 0, 150, 735)
        // context.drawImage(img, 130 * 5, 0, 150, 735, 0, 0, 150, 735)
        // context.drawImage(img, 130 * 6, 0, 150, 735, 0, 0, 150, 735)
        // context.drawImage(img, 130 * 7, 0, 150, 735, 0, 0, 150, 735)

        // 动画其实就是让多个图片在一定间隔内切换
        let setup = 0;
        setInterval(() => {
            context.clearRect(0, 0, canvas.width, canvas.height);
            context.drawImage(img, 130 * setup, 0, 150, 735, 0, 0, 150, 735)
            setup++
            setup %= 8;
        }, 100);
    }
</script>